package com.chixing.controller;

import com.chixing.pojo.Coupon;
import com.chixing.pojo.Customer;
import com.chixing.service.CouponService;
import com.chixing.service.PointService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
@RestController
public class CouponController {
   @Autowired
    private CouponService couponService;

   @GetMapping("coupon/coupon/{coupon_status}")
   @ResponseBody
   public ServerResponse getByAjax(HttpSession session, @PathVariable("coupon_status") Integer coupon_status){
       Customer customer = (Customer) session.getAttribute("loginCustomer");
       Integer cusId = customer.getCusId();
       return couponService.getByStatus(cusId,coupon_status);
   }
   @GetMapping("saveorder")
   @ResponseBody
   public String getByPage(HttpSession session,String orderNum){
       Customer customer = (Customer) session.getAttribute("loginCustomer");
       ServerResponse serverResponse1 = couponService.getByStatus(customer.getCusId(),0);
       System.out.println("返回的结果是coupon："+serverResponse1);
       return "redirect:myNewOrder?orderNum="+orderNum;
   }
    @GetMapping("order_payment/order_reserve")
    @ResponseBody
   public ServerResponse getById(@PathVariable("couponId") Integer couponId){
       return couponService.getById(couponId);
    }
   @RequestMapping(value = "coupon/coupon", method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse save(Coupon coupon){

       ServerResponse serverResponse3 = couponService.save(coupon);
       return serverResponse3;
   }
   @DeleteMapping("coupon/coupon/{couId}")
   @ResponseBody
   public ServerResponse delete(@PathVariable("couId") Integer couId){
        return couponService.delete(couId);
   }


}
